import {WidgetClass} from "./widget";

// 设备小组件布局组件
export class WidgetDeviceLayout extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {ports, UI} = options;
    if (UI) {
      this.UI.data = UI.data;
    } else {
      this.UI.data = {
        direction: 'horizontal',
        offsetX: 0,
        offsetY: 0,
        rows: 3,
        columns: 8,
        gapX: 16,
        gapY: 16,
        unitSize: 180,
        gridColor: '#F7F7F7',
        hoverColor: '#FAAD1433'
      };
    }
    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      values: [...superState.values],
      events: [
        {
          name: "抬起事件",
          key: `onTap-${this.id}`,
          eventType: "onTap",
          type: "event",
          action: [],
        },
        {
          name: "按下事件",
          key: `tapDown-${this.id}`,
          type: "event",
          eventType: "tapDown",
          action: [],
        },
        {
          name: "长按事件",
          key: `longPress-${this.id}`,
          eventType: "longPress",
          type: "event",
          value: {
            time: 1 //长按触发时间(秒)
          },
          action: [],
        },
      ],
    };
  }
}
